﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class UIVAART : ViewBase
    {
        public UIVAART()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MESSAGES += "WS2VA;";
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded) return; 
            if (!IsMasterFromMV)
            {
                MV = new VVAART();
                this.DataContext = MV;
            }
            //FTAUTOSUM = true;
            //TCOUNT1 = "任务书个数";  
            base.Window_Loaded(sender, e); 
        }
        public DataSet AFSPageLoad(DataRow dwData)
        {
            DataSet Set = new DataSet();
            int idx = 0;
            int rows = 100;
            while (true)
            {
                SResult = TMV.QVA06AFSEX(dwData, idx, rows);
                Set.Merge(SResult);
                if (SResult.Tables[0].Rows.Count == 0)
                    break; 
                idx++;
            }
            return Set;

        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            try
            {
                dwVA = dwMaster; 
                if (dwMaster == null)
                {
                    KEY = "";
                    PRART = ""; 
                    WSPRICE = "0";
                    CURRENCY = "";
                    PRMEEH = "";
                    TXTISIND = "";
                    VAPR = "";
                }
                else
                { 
                    KEY = dwMaster["VAAKOLL"].ToString() + dwMaster["VAAART"].ToString();
                
                    if(IsShowTxt)
                    {
                        TXTISIND = KEY.PadRight(60);
                    }

                    VAAKOLL = TMV.VAAKOLL;
                    VAAPRGR = TMV.VAAPRGR;                   
                    PRART = dwMaster["VAAARTST"].ToString() + dwMaster["VAADART"].ToString() + dwMaster["VAADVAR"].ToString() + dwMaster["VAABEZ"].ToString();
                    string PR = dwMaster["VAAARTWEB"].ToString().PadRight(15);
                    WSPRICE = PR.Substring(0, 8);
                    CURRENCY = PR.Substring(8, 3);
                    PRMEEH = PR.Substring(12, 3);
                    if (dwMaster["VAANEUDAT"].ToString().Trim() == "0")
                    {
                        dwMaster["VAANEUDAT"] = MV.date;
                    }
                    VAPR = "VA" + dwMaster["VAANEUDAT"].ToString().Substring(2, 6)
                        + "OF"
                        + CURRENCY + dwMaster["VAAKOLL"].ToString() + dwMaster["VAAART"].ToString();
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public bool IsReady = false; 
        public virtual void ImportExcel(object sender, RoutedEventArgs e)
        {



        }
        public override void NewCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!IsReady)
            {
                app.Mandant = "99";
                QueryCommand(null, null);
                app.Mandant = "00";
            }
            try
            {
                
                if (!IsNew)
                {                    
                    IsNew = true; 
                    //MessageBox.Show("请先输入必要信息");                    
                    return;
                }
                if (!IsSelfART)
                {
                    NART = EXART;
                }
                else
                {
                    if (PRODGRP.Trim().Length == 0)
                    {
                        MessageBox.Show("请先输入产品组");
                        return;
                    }
                }
                if (NART.Trim().Length == 0)
                {
                    MessageBox.Show("请先输入品种编号");
                    return;
                }
                if (EXART.Trim().Length == 0)
                {
                    MessageBox.Show("请先输入供应商品种编号");
                    return;
                }
                if (ARTGRP.Trim().Length == 0)
                {
                    ARTGRP = "   ";
                }
                if (!IsSameProdArt)
                {
                    if (EXART.Trim().Length == 0)
                    {
                        MessageBox.Show("请先定义生产品种");
                        return;
                    }
                }
                 
                PM["KOLL"] = KOLL.PadRight(5);
                PM["ARTST"] = ARTST.PadRight(1);
                PM["ART"] = NART.PadRight(24);
                PM["VAAPRGR"] = PRODGRP.PadRight(3);
                PM["VAAARTGRP"] = ARTGRP.PadRight(3);
                PM["EXART"] = EXART.PadRight(24);
                PM["DES"] = " "; 
                ((VVAART)MV).NEWVAART(PM);
                WSCREATE(PM);
                vwMaster.View.MoveCurrentToFirst();
                base.NewCommand(sender, e);
                IsNew = false;
                ART = "";
                DES = "";
                FARBE = ""; 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
                MessageBox.Show(ex.Message);
            }
        }
        public virtual void WSCREATE(Dictionary<string,object>pm)
        {

        }
        public override void EditCommand(object sender, RoutedEventArgs e)
        {
            base.EditCommand(sender, e);
        }

        public override void DeleteCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            base.DeleteCommand(sender, e);
            if (dwMaster == null)
                return;
            TMV.DeleteVAART(dwMaster, 1);

            string _VAAKOLL = dwMaster["VAAKOLL"].ToString();
            string _VAAART = dwMaster["VAAART"].ToString();
            vwMaster.View.MoveCurrentTo(-1);
            string filter = "VAAKOLL='" + _VAAKOLL + "' AND VAAART='" + _VAAART + "'";
            DataRow[] rows = TBMain.Select(filter);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
        }

        public override void CopyCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (((VVAART)MV).ART.Trim().Length == 0)
            {
                MessageBox.Show("请先输入品种编号");
                return;
            }
            PM["TART"] = MV.ART;
            PM["dwSrc"] = dwMaster;
            PM["IsSameProdArt"] =IsSameProdArt;
            TMV.Copy(PM);
            MV.ART = "";
            base.CopyCommand(sender, e); 
            vwMaster.View.MoveCurrentToFirst();

        }
        

        public void btnGetNART_Click(object sender, RoutedEventArgs e)
        {
            if (PRODGRP.Trim().Length == 0)
            {
                MessageBox.Show("请先选择产品组");
                return;
            }
            if (KOLL.Trim().Length == 0)
            {
                MessageBox.Show("请先选择季节");
                return;
            }
            while (true)
            {
                string ARTNR = VSDDAT.SD22.GETNEXT("0022", "  ", KOLL.Trim() + "-" + PRODGRP.Trim());
                NART = Helper.Left(PRODGRP.Trim() + Helper.Right(ARTNR, 3).PadRight(24), 24);
                dwData = TBMain.NewRow();
                dwData["VAAMANDANT"] = app.Mandant;
                dwData["VAAKOLL"] = KOLL;
                dwData["VAAART"] = Helper.Left(NART.PadRight(24), 24);
                SResult = ((VVAART)MV).QueryVAART(dwData, 5);
                if (SResult.Tables[0].Rows.Count == 0)
                    break;
            }
            if (IsSameProdArt)
            {
                EXART = NART;
            }
            else
            {
                EXART = "";
            }
            dwData = TBMain.NewRow();
            dwData["VAAMANDANT"] = "**";
            SResult = ((VVAART)MV).QueryVAART(dwData, 6);
            TBMain.Merge(SResult.Tables[0], false, MissingSchemaAction.AddWithKey);
            //MergeData(SResult, true);
        }
        public void SAVEVA(DataRow _dwVA)
        {
            _dwVA["VAAAENDBEN"] = app.User;
            _dwVA["VAAAENDDAT"] = MV.date;
            TMV.UpdateVAART(_dwVA, 0);
        }

        public override void LOADBYAUF()
        {
            base.LOADBYAUF();
            TBMain.Clear();
            if (ORDERNUM.Length < 29)
                return;
            dwData = TBMain.NewRow();
            dwData["VAAMANDANT"] = app.Mandant;
            dwData["VAAKOLL"] = ORDERNUM.Substring(0, 5);
            dwData["VAAART"] = ORDERNUM.Substring(5, 24);
            SResult = TMV.QVA02(dwData);
            MergeData(SResult, true, true);
        }
    }
    public partial class UIVAART : ViewBase
    {
        #region ==VAPR===========
        public static readonly DependencyProperty VAPRProperty = DependencyProperty.Register("VAPR",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVAPRChanged));
        public string VAPR
        {
            get
            {
                return (string)GetValue(VAPRProperty);
            }
            set
            {
                SetValue(VAPRProperty, value);
            }
        }
        private static void OnVAPRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.VAPR = (string)e.NewValue;
            }
        }
        #endregion
        public VVAART TMV
        {
            get
            {
                return (VVAART)MV;
            }
        }
        #region ==IsKOLLManage===========
        public static readonly DependencyProperty IsKOLLManageProperty = DependencyProperty.Register("IsKOLLManage",
        typeof(bool), typeof(UIVAART),
        new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsKOLLManageChanged));
        public bool IsKOLLManage
        {
            get
            {
                return (bool)GetValue(IsKOLLManageProperty);
            }
            set
            {
                SetValue(IsKOLLManageProperty, value);
            }
        }
        private static void OnIsKOLLManageChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.IsKOLLManage = (bool)e.NewValue;
                src.OnIsKOLLManageChg((bool)e.NewValue);
            }
        }
        public virtual void OnIsKOLLManageChg(bool value)
        {

        }
        #endregion
     
        #region ==CART===========
        public static readonly DependencyProperty CARTProperty = DependencyProperty.Register("CART",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCARTChanged));
        public string CART
        {
            get
            {
                return (string)GetValue(CARTProperty);
            }
            set
            {
                SetValue(CARTProperty, value);
                OnCARTChg(value); 
            }
        }
        private static void OnCARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.CART = (string)e.NewValue;
            }
        }
        public virtual void OnCARTChg(string value)
        { }
        #endregion

        #region ==IsSelfART===========
        public static readonly DependencyProperty IsSelfARTProperty = DependencyProperty.Register("IsSelfART",
            typeof(bool), typeof(UIVAART),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsSelfARTChanged));
        public bool IsSelfART
        {
            get
            {
                return (bool)GetValue(IsSelfARTProperty);
            }
            set
            {
                SetValue(IsSelfARTProperty, value);
            }
        }
        private static void OnIsSelfARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.IsSelfART = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsImageMax===========
        public static readonly DependencyProperty IsImageMaxProperty = DependencyProperty.Register("IsImageMax",
        typeof(bool), typeof(UIVAART),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsImageMaxChanged));
        public bool IsImageMax
        {
            get
            {
                return (bool)GetValue(IsImageMaxProperty);
            }
            set
            {
                SetValue(IsImageMaxProperty, value);
                OnImageMaxChg(value);
            }
        }
        private static void OnIsImageMaxChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.IsImageMax = (bool)e.NewValue;
            }
        }
        public virtual void OnImageMaxChg(bool ismax)
        { 
        }
        #endregion

        #region ==MB===========
        public static readonly DependencyProperty MBProperty = DependencyProperty.Register("MB",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMBChanged));
        public string MB
        {
            get
            {
                return (string)GetValue(MBProperty);
            }
            set
            {
                SetValue(MBProperty, value);
            }
        }
        private static void OnMBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.MB = (string)e.NewValue;
            }
        }
        #endregion
       
        #region ==MD===========
        public static readonly DependencyProperty MDProperty = DependencyProperty.Register("MD",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMDChanged));
        public string MD
        {
            get
            {
                return (string)GetValue(MDProperty);
            }
            set
            {
                SetValue(MDProperty, value);
            }
        }
        private static void OnMDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.MD = (string)e.NewValue;
            }
        }
        #endregion
        #region ==MW===========
        public static readonly DependencyProperty MWProperty = DependencyProperty.Register("MW",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMWChanged));
        public string MW
        {
            get
            {
                return (string)GetValue(MWProperty);
            }
            set
            {
                SetValue(MWProperty, value);
            }
        }
        private static void OnMWChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.MW = (string)e.NewValue;
            }
        }
        #endregion
        #region ==MS===========
        public static readonly DependencyProperty MSProperty = DependencyProperty.Register("MS",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMSChanged));
        public string MS
        {
            get
            {
                return (string)GetValue(MSProperty);
            }
            set
            {
                SetValue(MSProperty, value);
            }
        }
        private static void OnMSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.MS = (string)e.NewValue;
            }
        }
        #endregion
        #region ==MZ===========
        public static readonly DependencyProperty MZProperty = DependencyProperty.Register("MZ",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMZChanged));
        public string MZ
        {
            get
            {
                return (string)GetValue(MZProperty);
            }
            set
            {
                SetValue(MZProperty, value);
            }
        }
        private static void OnMZChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.MZ = (string)e.NewValue;
            }
        }
        #endregion
        #region ==LIEFNR===========
        public static readonly DependencyProperty LIEFNRProperty = DependencyProperty.Register("LIEFNR",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLIEFNRChanged));
        public string LIEFNR
        {
            get
            {
                return (string)GetValue(LIEFNRProperty);
            }
            set
            {
                SetValue(LIEFNRProperty, value);
                OnLIEFNRChg(value);
            }
        }
        private static void OnLIEFNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.LIEFNR = (string)e.NewValue;
            }
        }
        public virtual void OnLIEFNRChg(string ls)
        { }
        #endregion

        #region ==WALIEFNR===========
        public static readonly DependencyProperty WALIEFNRProperty = DependencyProperty.Register("WALIEFNR",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWALIEFNRChanged));
        public string WALIEFNR
        {
            get
            {
                return (string)GetValue(WALIEFNRProperty);
            }
            set
            {
                SetValue(WALIEFNRProperty, value);
                OnWALIEFNRChg(value);
            }
        }
        private static void OnWALIEFNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.WALIEFNR = (string)e.NewValue;
            }
        }
        public virtual void OnWALIEFNRChg(string ls)
        { }
        #endregion
        #region ==LSLIEFNA===========
        public static readonly DependencyProperty LSLIEFNAProperty = DependencyProperty.Register("LSLIEFNA",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLSLIEFNAChanged));
        public string LSLIEFNA
        {
            get
            {
                return (string)GetValue(LSLIEFNAProperty);
            }
            set
            {
                SetValue(LSLIEFNAProperty, value);
                OnLSLIEFNAChg(value);
            }
        }
        private static void OnLSLIEFNAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.LSLIEFNA = (string)e.NewValue;
            }
        }
        public virtual void OnLSLIEFNAChg(string ls)
        { }
        #endregion
         

        #region ==NART===========
        public static readonly DependencyProperty NARTProperty = DependencyProperty.Register("NART",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnNARTChanged));
        public string NART
        {
            get
            {
                return (string)GetValue(NARTProperty);
            }
            set
            {
                SetValue(NARTProperty, value);
            }
        }
        private static void OnNARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.NART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==EXART===========
        public static readonly DependencyProperty EXARTProperty = DependencyProperty.Register("EXART",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEXARTChanged));
        public string EXART
        {
            get
            {
                return (string)GetValue(EXARTProperty);
            }
            set
            {
                SetValue(EXARTProperty, value);
            }
        }
        private static void OnEXARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.EXART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PRART===========
        public static readonly DependencyProperty PRARTProperty = DependencyProperty.Register("PRART",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPRARTChanged));
        public string PRART
        {
            get
            {
                return (string)GetValue(PRARTProperty);
            }
            set
            {
                SetValue(PRARTProperty, value);
            }
        }
        private static void OnPRARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.PRART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VAAKOLL===========
        public static readonly DependencyProperty VAAKOLLProperty = DependencyProperty.Register("VAAKOLL",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVAAKOLLChanged));
        public string VAAKOLL
        {
            get
            {
                return (string)GetValue(VAAKOLLProperty);
            }
            set
            {
                SetValue(VAAKOLLProperty, value);
            }
        }
        private static void OnVAAKOLLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.VAAKOLL = (string)e.NewValue;
            }
        }
       
        #endregion

        #region ==VAAPRGR===========
        public static readonly DependencyProperty VAAPRGRProperty = DependencyProperty.Register("VAAPRGR",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVAAPRGRChanged));
        public string VAAPRGR
        {
            get
            {
                return (string)GetValue(VAAPRGRProperty);
            }
            set
            {
                SetValue(VAAPRGRProperty, value);
            }
        }
        private static void OnVAAPRGRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.VAAPRGR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PRFART===========
        public static readonly DependencyProperty PRFARTProperty = DependencyProperty.Register("PRFART",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPRFARTChanged));
        public string PRFART
        {
            get
            {
                return (string)GetValue(PRFARTProperty);
            }
            set
            {
                SetValue(PRFARTProperty, value);
            }
        }
        private static void OnPRFARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.PRFART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VALBTYP===========
        public static readonly DependencyProperty VALBTYPProperty = DependencyProperty.Register("VALBTYP",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVALBTYPChanged));
        public string VALBTYP
        {
            get
            {
                return (string)GetValue(VALBTYPProperty);
            }
            set
            {
                SetValue(VALBTYPProperty, value);
            }
        }
        private static void OnVALBTYPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.VALBTYP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PRODGRP===========
        public static readonly DependencyProperty PRODGRPProperty = DependencyProperty.Register("PRODGRP",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPRODGRPChanged));
        public string PRODGRP
        {
            get
            {
                return (string)GetValue(PRODGRPProperty);
            }
            set
            {
                SetValue(PRODGRPProperty, value); 
            }
        }
        private static void OnPRODGRPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.PRODGRP = (string)e.NewValue;
                src.OnPRODGRPChg((string)e.NewValue);

            }
        }
        public virtual void OnPRODGRPChg(string value)
        {
            if (!IsEdit)
                return;
            if (MV == null)
                return;
            TMV.VAAPRGR = value.PadRight(3);
        }
        #endregion

        #region ==ARTGRP===========
        public static readonly DependencyProperty ARTGRPProperty = DependencyProperty.Register("ARTGRP",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnARTGRPChanged));
        public string ARTGRP
        {
            get
            {
                return (string)GetValue(ARTGRPProperty);
            }
            set
            {
                SetValue(ARTGRPProperty, value);
               
            }
        }
        private static void OnARTGRPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.ARTGRP = (string)e.NewValue;
                src.OnARTGRPChg((string)e.NewValue);
            }
        }
        public virtual void OnARTGRPChg(string value)
        {
            if (!IsEdit)
                return;
            if (MV == null)
                return;
            TMV.VAAARTGRP = value.PadRight(3); 
        }
        #endregion

        #region ==DEFWSTXT===========
        public static readonly DependencyProperty DEFWSTXTProperty = DependencyProperty.Register("DEFWSTXT",
            typeof(List<string>), typeof(UIVAART),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDEFWSTXTChanged));
        public List<string> DEFWSTXT
        {
            get
            {
                return (List<string>)GetValue(DEFWSTXTProperty);
            }
            set
            {
                SetValue(DEFWSTXTProperty, value);
            }
        }
        private static void OnDEFWSTXTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.DEFWSTXT = (List<string>)e.NewValue;
            }
        }
        #endregion

        #region ==IsExtProd===========
        public static readonly DependencyProperty IsExtProdProperty = DependencyProperty.Register("IsExtProd",
            typeof(bool), typeof(UIVAART),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsExtProdChanged));
        public bool IsExtProd
        {
            get
            {
                return (bool)GetValue(IsExtProdProperty);
            }
            set
            {
                SetValue(IsExtProdProperty, value);
            }
        }
        private static void OnIsExtProdChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.IsExtProd = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsSameProdArt===========
        public static readonly DependencyProperty IsSameProdArtProperty = DependencyProperty.Register("IsSameProdArt",
            typeof(bool), typeof(UIVAART),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsSameProdArtChanged));
        public bool IsSameProdArt
        {
            get
            {
                return (bool)GetValue(IsSameProdArtProperty);
            }
            set
            {
                SetValue(IsSameProdArtProperty, value);
            }
        }
        private static void OnIsSameProdArtChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.IsSameProdArt = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowTxt===========
        public static readonly DependencyProperty IsShowTxtProperty = DependencyProperty.Register("IsShowTxt",
            typeof(bool), typeof(UIVAART),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowTxtChanged));
        public bool IsShowTxt
        {
            get
            {
                return (bool)GetValue(IsShowTxtProperty);
            }
            set
            {
                SetValue(IsShowTxtProperty, value);
            }
        }
        private static void OnIsShowTxtChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.IsShowTxt = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==dwVA===========
        public static readonly DependencyProperty dwVAProperty = DependencyProperty.Register("dwVA",
            typeof(DataRow), typeof(UIVAART),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVAChanged));
        public DataRow dwVA
        {
            get
            {
                return (DataRow)GetValue(dwVAProperty);
            }
            set
            {
                SetValue(dwVAProperty, value);
                if (MV == null)
                    return;
                ((VVAART)MV).dwVA = value;


            }
        }
        private static void OndwVAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.dwVA = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==WSPRICE===========
        public static readonly DependencyProperty WSPRICEProperty = DependencyProperty.Register("WSPRICE",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWSPRICEChanged));
        public string WSPRICE
        {
            get
            {
                return (string)GetValue(WSPRICEProperty);
            }
            set
            {
                SetValue(WSPRICEProperty, value);
                if (!IsEdit)
                    return;
                if (dwMaster == null)
                    return;
                if (value == null)
                    return;
                if (value.Trim().Length == 0)
                    return;
                if (WSPRICE.Trim() == "0")
                    return;
                if (WSPRICE.Trim() == "0.00")
                    return;
                if (WSPRICE.Trim() == "0.0")
                    return;

                VAAARTWEB = Helper.Left(
                  Helper.Left(WSPRICE.PadRight(8), 8)
                  + Helper.Left(CURRENCY.PadRight(3), 3)
                  + "/"
                  + PRMEEH.PadRight(24), 24);
            }
        }
        private static void OnWSPRICEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.WSPRICE = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VAAARTWEB===========
        public static readonly DependencyProperty VAAARTWEBProperty = DependencyProperty.Register("VAAARTWEB",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVAAARTWEBChanged));
        public string VAAARTWEB
        {
            get
            {
                return (string)GetValue(VAAARTWEBProperty);
            }
            set
            {
                SetValue(VAAARTWEBProperty, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                ((VVAART)MV).VAAARTWEB = value;
            }
        }
        private static void OnVAAARTWEBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.VAAARTWEB = (string)e.NewValue;
            }
        }
        #endregion

        #region ==CURRENCY===========
        public static readonly DependencyProperty CURRENCYProperty = DependencyProperty.Register("CURRENCY",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCURRENCYChanged));
        public string CURRENCY
        {
            get
            {
                return (string)GetValue(CURRENCYProperty);
            }
            set
            {
                SetValue(CURRENCYProperty, value);
                if (!IsEdit)
                    return;
                if (dwMaster == null)
                    return;
                if (value == null)
                    return;
                if (value.Trim().Length == 0)
                    return;
                //dwMaster["VAAARTWEB"] 
                    VAAARTWEB= Helper.Left(
               Helper.Left(WSPRICE.PadRight(8), 8)
               + Helper.Left(CURRENCY.PadRight(3), 3)
               + "/"
               + PRMEEH.PadRight(24), 24);
            }
        }
        private static void OnCURRENCYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.CURRENCY = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PRMEEH===========
        public static readonly DependencyProperty PRMEEHProperty = DependencyProperty.Register("PRMEEH",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPRMEEHChanged));
        public string PRMEEH
        {
            get
            {
                return (string)GetValue(PRMEEHProperty);
            }
            set
            {
                SetValue(PRMEEHProperty, value);
                if (!IsEdit)
                    return;
                if (dwMaster == null)
                    return;
                if (value == null)
                    return;
                if (value.Trim().Length == 0)
                    return;
                //dwMaster["VAAARTWEB"] 
                VAAARTWEB = Helper.Left(
               Helper.Left(WSPRICE.PadRight(8), 8)
               + Helper.Left(CURRENCY.PadRight(3), 3)
               + "/"
               + PRMEEH.PadRight(24), 24);
            }
        }
        private static void OnPRMEEHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.PRMEEH = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsAutoVA===========
        public static readonly DependencyProperty IsAutoVAProperty = DependencyProperty.Register("IsAutoVA",
            typeof(bool), typeof(UIVAART),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsAutoVAChanged));
        public bool IsAutoVA
        {
            get
            {
                return (bool)GetValue(IsAutoVAProperty);
            }
            set
            {
                SetValue(IsAutoVAProperty, value);
            }
        }
        private static void OnIsAutoVAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.IsAutoVA = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==FBRTU===========
        public static readonly DependencyProperty FBRTUProperty = DependencyProperty.Register("FBRTU",
            typeof(double), typeof(UIVAART),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFBRTUChanged));
        public double FBRTU
        {
            get
            {
                return (double)GetValue(FBRTUProperty);
            }
            set
            {
                SetValue(FBRTUProperty, value);
                OnFBRTUChg(value);
            }
        }
        private static void OnFBRTUChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.FBRTU = (double)e.NewValue;
            }
        }
        public virtual void OnFBRTUChg(double value)
        { }
        #endregion
        #region ==FBRTL===========
        public static readonly DependencyProperty FBRTLProperty = DependencyProperty.Register("FBRTL",
            typeof(double), typeof(UIVAART),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFBRTLChanged));
        public double FBRTL
        {
            get
            {
                return (double)GetValue(FBRTLProperty);
            }
            set
            {
                SetValue(FBRTLProperty, value);
                OnFBRTLChg(value);
            }
        }
        private static void OnFBRTLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.FBRTL = (double)e.NewValue;
            }
        }
        public virtual void OnFBRTLChg(double value)
        { }
        #endregion
        #region ==FGRLFD===========
        public static readonly DependencyProperty FGRLFDProperty = DependencyProperty.Register("FGRLFD",
            typeof(double), typeof(UIVAART),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFGRLFDChanged));
        public double FGRLFD
        {
            get
            {
                return (double)GetValue(FGRLFDProperty);
            }
            set
            {
                SetValue(FGRLFDProperty, value);
                OnFGRLFDChg(value);
            }
        }
        private static void OnFGRLFDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.FGRLFD = (double)e.NewValue;
            }
        }
        public virtual void OnFGRLFDChg(double value)
        { }
        #endregion
        #region ==FGRQM===========
        public static readonly DependencyProperty FGRQMProperty = DependencyProperty.Register("FGRQM",
            typeof(double), typeof(UIVAART),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFGRQMChanged));
        public double FGRQM
        {
            get
            {
                return (double)GetValue(FGRQMProperty);
            }
            set
            {
                SetValue(FGRQMProperty, value);
                OnFGRQMChg(value);
            }
        }
        private static void OnFGRQMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.FGRQM = (double)e.NewValue;
            }
        }
        public virtual void OnFGRQMChg(double value)
        { }
        #endregion
        #region ==FFDDIK===========
        public static readonly DependencyProperty FFDDIKProperty = DependencyProperty.Register("FFDDIK",
            typeof(double), typeof(UIVAART),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFFDDIKChanged));
        public double FFDDIK
        {
            get
            {
                return (double)GetValue(FFDDIKProperty);
            }
            set
            {
                SetValue(FFDDIKProperty, value);
                OnFFDDIKChg(value);
            }
        }
        private static void OnFFDDIKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.FFDDIK = (double)e.NewValue;
            }
        }
        public virtual void OnFFDDIKChg(double value)
        { }
        #endregion
        #region ==FFDDIS===========
        public static readonly DependencyProperty FFDDISProperty = DependencyProperty.Register("FFDDIS",
            typeof(double), typeof(UIVAART),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFFDDISChanged));
        public double FFDDIS
        {
            get
            {
                return (double)GetValue(FFDDISProperty);
            }
            set
            {
                SetValue(FFDDISProperty, value);
                OnFFDDISChg(value);
            }
        }
        private static void OnFFDDISChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.FFDDIS = (double)e.NewValue;
            }
        }
        public virtual void OnFFDDISChg(double value)
        { }
        #endregion
        #region ==FDDIM===========
        public static readonly DependencyProperty FDDIMProperty = DependencyProperty.Register("FDDIM",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFDDIMChanged));
        public string FDDIM
        {
            get
            {
                return (string)GetValue(FDDIMProperty);
            }
            set
            {
                SetValue(FDDIMProperty, value);
                OnFDDIMChg(value);
            }
        }
        private static void OnFDDIMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.FDDIM = (string)e.NewValue;
            }
        }
        public virtual void OnFDDIMChg(string value)
        { }
        #endregion 
        #region ==DES===========
        public static readonly DependencyProperty DESProperty = DependencyProperty.Register("DES",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDESChanged));
        public string DES
        {
            get
            {
                return (string)GetValue(DESProperty);
            }
            set
            {
                SetValue(DESProperty, value);
                OnDESChg(value);
            }
        }
        private static void OnDESChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.DES = (string)e.NewValue;
            }
        }
        public virtual void OnVAABEZChg(string value)
        { }
        #endregion 
        #region ==VAAZOLLTNR1===========
        public static readonly DependencyProperty VAAZOLLTNR1Property = DependencyProperty.Register("VAAZOLLTNR1",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVAAZOLLTNR1Changed));
        public string VAAZOLLTNR1
        {
            get
            {
                return (string)GetValue(VAAZOLLTNR1Property);
            }
            set
            {
                SetValue(VAAZOLLTNR1Property, value);
                OnVAAZOLLTNR1Chg(value);
            }
        }
        private static void OnVAAZOLLTNR1Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.VAAZOLLTNR1 = (string)e.NewValue;
            }
        }
        public virtual void OnVAAZOLLTNR1Chg(string value)
        { }
        #endregion 
        #region ==VAAREFART===========
        public static readonly DependencyProperty VAAREFARTProperty = DependencyProperty.Register("VAAREFART",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVAAREFARTChanged));
        public string VAAREFART
        {
            get
            {
                return (string)GetValue(VAAREFARTProperty);
            }
            set
            {
                SetValue(VAAREFARTProperty, value);
                OnVAAREFARTChg(value);
            }
        }
        private static void OnVAAREFARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.VAAREFART = (string)e.NewValue;
            }
        }
        public virtual void OnVAAREFARTChg(string value)
        { }
        #endregion 
        #region ==VAAARTFAM===========
        public static readonly DependencyProperty VAAARTFAMProperty = DependencyProperty.Register("VAAARTFAM",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVAAARTFAMChanged));
        public string VAAARTFAM
        {
            get
            {
                return (string)GetValue(VAAARTFAMProperty);
            }
            set
            {
                SetValue(VAAARTFAMProperty, value); 
            }
        }
        private static void OnVAAARTFAMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.VAAARTFAM = (string)e.NewValue;
                src.OnVAAARTFAMChg((string)e.NewValue);
            }
        }
        public virtual void OnVAAARTFAMChg(string value)
        { }
        #endregion 

        #region ==EXCL===========
        public static readonly DependencyProperty EXCLProperty = DependencyProperty.Register("EXCL",
            typeof(string), typeof(UIVAART),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEXCLChanged));
        public string EXCL
        {
            get
            {
                return (string)GetValue(EXCLProperty);
            }
            set
            {
                SetValue(EXCLProperty, value);
               
            }
        }
        private static void OnEXCLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.EXCL = (string)e.NewValue;
                src.OnEXCLChg((string)e.NewValue);
            }
        }
        public virtual void OnEXCLChg(string value)
        {
            TMV.VAAEXCL = value;
        }
        #endregion 
      
        #region ==IsComposition===========
        public static readonly DependencyProperty IsCompositionProperty = DependencyProperty.Register("IsComposition",
            typeof(bool), typeof(UIVAART),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCompositionChanged));
        public bool IsComposition
        {
            get
            {
                return (bool)GetValue(IsCompositionProperty);
            }
            set
            {
                SetValue(IsCompositionProperty, value);
            }
        }
        private static void OnIsCompositionChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAART;
            if (src != null)
            {
                src.IsComposition = (bool)e.NewValue;
                src.OnIsCompositionChg((bool)e.NewValue);
            }
        }
        public virtual void OnIsCompositionChg(bool value)
        {

        }
        #endregion
    }
}
